﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Xiami.util;
using Xiami.lib;

namespace Xiami {
    public partial class XXiami : Form {

        protected XDialog _dialog;
        private XFile _file;

        protected static string formName = "虾米替换音乐文件工具";

        public XXiami() {
            InitializeComponent();
            this._dialog = new XDialog(XXiami.formName);
        }

        private void open_url_Click(object sender, EventArgs e) {
            
        }

        private void reset_copy_info_Click(object sender, EventArgs e) {
            this.srcDir.Text    = "";
            this.desDir.Text    = "";
        }

        private void start_copy_Click(object sender, EventArgs e) {
            this.validateCopyGroup();
            this.execLog.Text = "";
            this._file = new XFile();
            this._file.setForm(this);
            this._file.setSrcDir(this.srcDir.Text);
            this._file.setDesDir(this.desDir.Text);
            this._file.setFileFormat(this.fileTypes.Text);
            this.setExecLog("正在复制...");
            if (false == this._file.copyFile()) {
                this.setExecLog(this._file.getErrorInfo());
            }
            this.setExecLog("复制完成！");
        }

        private Boolean validateCopyGroup() {
            if(this.srcDir.Text == "") {
                this._dialog.showWarn("源目录不能这空！");
                this.srcDir.Focus();
                return false;
            }
            if(this.desDir.Text == "") {
                this._dialog.showWarn("目标目录不能为空！");
                this.desDir.Focus();
                return false;
            }
            if (this.fileTypes.Text == "") {
                this._dialog.showWarn("需要复制的文件类型不能为空！");
                this.fileTypes.Focus();
                return false;
            }

            return true;
        }

        public void setExecLog(string msg) {
            this.execLog.Text += msg + "\r\n";            
        }

    }
}
